package org.jetnuke.modules.admin.stories;

import java.util.Calendar;
import java.util.GregorianCalendar;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.velocity.VelocityContext;
import org.jetnuke.common.ActionForward;
import org.jetnuke.common.IAction;
import org.jetnuke.common.IAdminInfo;
import org.jetnuke.common.IModuleInfo;
import org.jetnuke.common.IUserInfo;
import org.jetnuke.dao.DataAccessDriver;
import org.jetnuke.entities.Queue;

public class Show implements IAction {
	int qid;

	public void setQid(int qid) {
		this.qid = qid;
	}

	public ActionForward exec(HttpServletRequest request,
			HttpServletResponse response, VelocityContext vc, IModuleInfo info,
			String op, IUserInfo ui, IAdminInfo ai) throws Exception {

		if (ai == null || (!ai.IsSuperUser()))
			return null;//Error;
		Queue story =  DataAccessDriver.getInst().newQueueDAO().retrieveByPK(qid);
		vc.put("queue", story);
		GregorianCalendar gc = new GregorianCalendar();
		vc.put("tday", new Integer(gc.get(Calendar.DATE)));
		vc.put("tmonth", new Integer(gc.get(Calendar.MONTH) + 1));
		vc.put("tyear", new Integer(gc.get(Calendar.YEAR)));
		vc.put("categories", DataAccessDriver.getInst().newStoriesCatDAO().selectAll());
				
				//stories_catPeer.doSelect(new Criteria()
				//.addAscendingOrderByColumn(stories_catPeer.TITLE)));
		vc.put("topics",  DataAccessDriver.getInst().newTopicsDAO().selectAllOrderTopicName());// topicsPeer.doSelect(new Criteria()
				//.addAscendingOrderByColumn(topicsPeer.TOPICTEXT)));
		vc.put("enc_story", story.getSTORY()); 
				
				//TextUtilities.replaceTags(TextUtilities
				//.replaceAmp(story.getSTORY())));
		vc.put("enc_story_ext",  story.getSTORYEXT());//  //TextUtilities.replaceTags(TextUtilities
				//.replaceAmp(story.getSTORYEXT())));
		return new ActionForward(op, info);
	}
}
